////////////////////////////////////////////////////////////////////////////
//
//  CryEngine Source File.
//  Copyright (C), Crytek, 1999-2010.
// -------------------------------------------------------------------------
//  File name: RefPicture.h
//  Version:   v1.00
//  Created:   20-04-2010 by Dongjoon Kim
//  Description:
// -------------------------------------------------------------------------  
//  History:
//
//////////////////////////////////////////////////////////////////////////// 

#ifndef __REFPICTURE_H__
#define __REFPICTURE_H__

#pragma once

#include "BaseObject.h"

class CMaterial;
class CEdMesh;

//////////////////////////////////////////////////////////////////////////
class CRefPicture : public CBaseObject
{
public:
	DECLARE_DYNCREATE(CRefPicture)

	//-----------------------------------------------------------------------------
	//!
	CRefPicture();

	//-----------------------------------------------------------------------------
	//!
	void Display( DisplayContext &dc );

	//-----------------------------------------------------------------------------
	//!
	bool HitTest( HitContext &hc );

	//-----------------------------------------------------------------------------
	//!
	void GetLocalBounds( AABB &box );

	//-----------------------------------------------------------------------------
	//!
	int MouseCreateCallback( CViewport *view,EMouseEvent event,CPoint &point,int flags );

	//-----------------------------------------------------------------------------
	//!
	XmlNodeRef Export( const CString &levelPath,XmlNodeRef &xmlNode );

protected:
	//-----------------------------------------------------------------------------
	//!
	void PostClone( CBaseObject *pFromObject,CObjectCloneContext &ctx );

	//-----------------------------------------------------------------------------
	//!
	bool CreateGameObject();

	//-----------------------------------------------------------------------------
	//!
	void Done();

	//-----------------------------------------------------------------------------
	//!
	void DeleteThis() { delete this; };

	//-----------------------------------------------------------------------------
	//!
	void InvalidateTM( int nWhyFlags );

	//-----------------------------------------------------------------------------
	//!
	void OnVariableChanged(IVariable*	piVariable);

	//-----------------------------------------------------------------------------
	//!
	void UpdateImage(const CString& picturePath);

	//-----------------------------------------------------------------------------
	//!
	void ApplyScale(float fScale);


	CVariable<CString>	mv_picFilepath;
	CVariable<float>	mv_scale;
	CVariable<float>	mv_opacity;

private:
	_smart_ptr<IMaterial>	m_pMaterial;
	IRenderNode*			m_pRenderNode;
	_smart_ptr<CEdMesh>		m_pGeometry;

	float				m_aspectRatio;
	AABB				m_bbox;
	Matrix34			m_invertTM;
};

//////////////////////////////////////////////////////////////////////////
class CRefPictureClassDesc : public CObjectClassDesc
{
public:

	REFGUID ClassID()
	{
		// {76ED2D33-95B5-4a54-A3C6-ED1B9D6DCEEE}
		static const GUID guid = 
		{ 0x76ed2d33, 0x95b5, 0x4a54, { 0xa3, 0xc6, 0xed, 0x1b, 0x9d, 0x6d, 0xce, 0xee } };
		return guid;
	}

	ObjectType GetObjectType() { return OBJTYPE_REFPICTURE; };

	const char* ClassName() { return "ReferencePicture"; }

	const char* Category() { return "Misc"; }

	CRuntimeClass* GetRuntimeClass() { return RUNTIME_CLASS(CRefPicture); }

};

#endif//__REFPICTURE_H__